package com.globant.rdm.iod.guice;

import org.apache.log4j.Logger;

import com.globant.rdm.domain.DomainModule;
import com.globant.rdm.iod.DomainObjectInjector;
import com.google.inject.Guice;
import com.google.inject.Injector;

public class GuiceAwareDomainObjectInjector implements DomainObjectInjector {

	private Injector i = Guice.createInjector(new DomainModule());

	private static final Logger logger = Logger.getLogger(GuiceAwareDomainObjectInjector.class);
	
	private static GuiceAwareDomainObjectInjector instance = new GuiceAwareDomainObjectInjector();

	public void resolveDependencies(final Object domainObject) {
		logger.debug("Starting injecting dependencies into " + domainObject.getClass().getName());
		i.injectMembers(domainObject);
		logger.debug("Dependencies injection for " + domainObject.getClass().getName() + " completed.");
	}

	public static GuiceAwareDomainObjectInjector getInstance() {
		return instance;
	}

}
